
// 创新与制造轮播图
document.addEventListener('DOMContentLoaded', function() {
	// 初始化两组轮播器
	initSlider('.research-container');
	initSlider('.research-container-left');

	function initSlider(containerSelector) {
		const container = document.querySelector(containerSelector);
		if (!container) return;

		const prevBtn = container.querySelector('.prev-btn');
		const nextBtn = container.querySelector('.next-btn');
		const slides = container.querySelectorAll('.image-slider li');
		let currentSlide = 0;

		// 显示指定索引的幻灯片
		function showSlide(index) {
			// 处理边界情况
			if (index >= slides.length) {
				index = 0; // 超过最后一张回到第一张
			} else if (index < 0) {
				index = slides.length - 1; // 小于第一张跳到最后一张
			}

			// 隐藏所有幻灯片
			slides.forEach(slide => {
				slide.style.opacity = '0';
				slide.style.transition = 'opacity 0.5s ease';
			});

			// 显示当前幻灯片
			slides[index].style.opacity = '1';
			currentSlide = index;
		}

		// 初始化显示第一张
		showSlide(0);

		// 添加事件监听
		if (prevBtn) {
			prevBtn.addEventListener('click', () => {
				showSlide(currentSlide - 1);
				
			});
		}

		if (nextBtn) {
			nextBtn.addEventListener('click', () => {
				showSlide(currentSlide + 1);
			});
		}
	}
});
